@extends("layouts.admin")
@section("_css")
    <link rel="stylesheet" href="/asset/css/custom/resources.css">
    <link rel="stylesheet" type="text/css" href="/asset/css/bootstrap-fileupload.min.css" />
    <link rel="stylesheet" type="text/css" href="/asset/js/jquery-tags-input/jquery.tagsinput.css" />
    <link rel="stylesheet" type="text/css" href="/asset/css/blog.css" />
@endsection
@section("_js")
    <script type="text/javascript" src="/asset/js/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/asset/js/bootstrap-fileupload.min.js"></script>
    <script src="/asset/js/jquery-tags-input/jquery.tagsinput.js"></script>
    <script src="/asset/js/tagsinput-init.js"></script>
    <script>
        $("#addCate").click(function(){
            var input_tpl ='<input id="new_cate" class="form-control" type="text" >';
            if( $("#new_cate").length == 0){
                $(this).after(input_tpl);
                $("#new_cate").focus();
            }

        });

        $(".right-box").on("keydown","#new_cate", function(e){
            var handleUrl = "/Admin/Blog/addCate";
            if(e.keyCode == 13){
                var _cate = $("#new_cate").val();
                var data = {
                    _cate:_cate
                }

                $.get(handleUrl,data,function(res){
                    var tpl = "<option value='"+res.data.id+"'>"+res.data.name+"</option>";
                    if(res && res.sta >0 ){
                        $("select[name=category]").append(tpl);
                        $("#new_cate").remove();
                    }
                },'json');

                return false;
            }
        })

        $(".right-box").on("blur","#new_cate", function(){
            $("#new_cate").remove();
        })
    </script>
@endsection
@section("main_content")
    <div class="form">
        <form method="POST" action="\Admin\Blog\{{$handleUrl}}" enctype="multipart/form-data" id="blog_form">
            <div class="left-box col-md-10">
                <span>标　　题</span>
                <input class="sy-form" type="text" name="title" value="{{$blogInfo->title or ''}}"/>
                <span class="right-span">介　　绍</span>
                <input class="sy-form introduce" type="text" name="summary" value="{{$blogInfo->summary or ''}}"/><br/><br/>
                <textarea class="form-control ckeditor" name="content" rows="6">{{$blogInfo->content or ''}}</textarea>
            </div>
            <div class="right-box col-md-2">
                <label for="" class="">图片</label>
                <div class="fileupload fileupload-new" data-provides="fileupload">
                    <div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
                        <img id = "upload_img" src="{{$blogInfo->img or ''}}" alt="" />
                        <input type="hidden" name="cate_img" value="">
                    </div>
                    <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                    <div>
                       <span class="btn btn-default btn-file" style="margin-left: 0px">
                           <span class="fileupload-new" ><i class="fa fa-paper-clip"></i>选择图片</span>
                           <span class="fileupload-exists"><i class="fa fa-undo"></i>更换图片</span>
                           <input type="file" name="main_img" class="" />
                       </span>
                        <a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload"><i class="fa fa-trash"></i>移除图片</a>
                    </div>
                </div>
                </br>
                <label for="" class="">分类</label>
                <select name="category" class="form-control m-bot15">
                    <option value="0">未分类</option>
                    @foreach($categories as $i)
                        <option value="{{$i->id}}" @if( $i->id == ($blogInfo?$blogInfo->category:0)) selected @endif >{{$i->name}}</option>
                    @endforeach
                </select>
                <span id="addCate" class="btn btn-info btn-xs">添加分类</span>
                </br>
                </br>
                <label for="" class="">自定义标签</label>
                <div class="tags">
                    <input id="tags_2" name="tags" type="text" class="tags" value="{{$blogInfo->tags or ''}}" />
                </div>
                </br>
                <input type="submit" name="submit" value="提交" class="btn btn-blue"/>
                <input type="reset" value="取消" class="btn btn-blue-border"/>
            </div>
            <?php echo csrf_field(); ?>
        </form>
    </div>
@endsection
